package com.ghck.server.dao.provider;

import org.apache.commons.lang3.StringUtils;

import com.ghck.server.model.Message;
import com.ghck.server.utils.IntegerUtil;
/**
 * 账号接口认证表  <br>
 * ajk_account <br>
 * v1.0 2016-05-01
 * @see com.ajk.server.dao.AjkAccountMapper
 */
 public class MessageMapperProvider {
 
	
 	public String list(Message message)
 	{
 		StringBuilder sb = new StringBuilder();
		sb.append("select * from t_message where 1 = 1 ");
		if(!StringUtils.isEmpty(message.getStartTime()) && !StringUtils.isEmpty(message.getEndTime())){
			sb.append(" and create_time >= #{startTime} and create_time <= #{endTime}");
		}else{
			if(!StringUtils.isEmpty(message.getStartTime())){
				sb.append(" and create_time >= #{startTime}  ");
			}
			if(!StringUtils.isEmpty(message.getEndTime())){
				sb.append(" and create_time <= #{endTime}  ");
			}
		}
		if(!StringUtils.isEmpty(message.getKeyword())){
			sb.append(" and title like concat('%',#{keyword},'%') ");
		}
		sb.append(" order by id desc ");
		return sb.toString();
 	}
 	
 	public String myList(Message message)
 	{
 		StringBuilder sb = new StringBuilder();
		sb.append("select a.id r_id,a.is_read,b.* from r_user_message a,t_message b where a.message_id = b.id and user_id = #{userId} order by id desc ");
		if(message.getStart() != null){
			sb.append(" limit #{start},#{limit} ");
		}
		return sb.toString();
 	}
 	
 }	